import tensorflow as tf

X = tf.Variable([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [7, 8, 1]]], dtype=tf.float32);

sum_0 = tf.reduce_sum(X, axis=0)
sum_1 = tf.reduce_sum(X, axis=1)
sum_0_1 = tf.reduce_sum(X, axis=[0, 1])
sum_1_0 = tf.reduce_sum(X, axis=[1, 0])

d_sum_0 = tf.gradients(sum_0, X)
d_sum_1 = tf.gradients(sum_1, X)
d_sum_0_1 = tf.gradients(sum_0_1, X)
d_sum_1_0 = tf.gradients(sum_1_0, X)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    
    print('------sum_0------')
    print(sess.run(sum_0))
    print('------sum_1------')
    print(sess.run(sum_1))
    print('------sum_0_1------')
    print(sess.run(sum_0_1))
    print('------sum_1_0------')
    print(sess.run(sum_1_0))
    
    print('------d_sum_0------')
    print(sess.run(d_sum_0))
    print('------d_sum_1------')
    print(sess.run(d_sum_1))
    print('------d_sum_0_1------')
    print(sess.run(d_sum_0_1))
    print('------d_sum_1_0------')
    print(sess.run(d_sum_1_0))